package org.lanqiao.tjut.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.TBAdminsBean;
import org.lanqiao.tjut.model.ModelFactory;
import org.lanqiao.tjut.myutils.MyUtils;

public class UserLoginServlet extends HttpServlet{
 private static final long serialVersionUID =1L;
 //初始化方法
 public void init(ServletConfig config) throws ServletException{
	 
 }
 //销毁方法
public void destroy() {
	// TODO Auto-generated method stub
	
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// TODO Auto-generated method stub
	System.out.println("这是进行的对客户端request请求的处理");
	//获取用户名密码
	String strName=req.getParameter("txtUserName");
	String strPsw=req.getParameter("txtUserPsw");
	System.out.println("获取的客户端的账号："+strName);
	System.out.println("获取的客户端的密码："+strPsw);
	
	//使用实体类进行传参
    TBAdminsBean adminB=MyUtils.getNewInstance(TBAdminsBean.class);
    //将前台页面传入值，赋值给实体变量
    adminB.setAdmins_name(strName);
    adminB.setAdmins_psw(strPsw);
    //调用model层进行登录验证的业务逻辑处理
    //获取登录用户信息
    List<TBAdminsBean> lstAdmins=ModelFactory.getUserLoginModelInstance().getUserLoginInfo(adminB);
 	//判断登录是否成功
    if(lstAdmins!=null&&lstAdmins.size()>0){
    	//使用重定向进行跳转
    	resp.sendRedirect("logined/logined.jsp");
    }else{
    	resp.sendRedirect("login.jsp");
    }	
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// TODO Auto-generated method stub
	doGet(req, resp);
}


 
}
